'use strict';
module.exports = {
	/**
	 * 查询剧每日数据
	 * @url admin/pages/kh/tjsj/tvmysj/getList 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { type } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------
		let dbName = "b_copyrightData"; // 表名
		if (userInfo.role.includes("admin")) {
			res = await vk.baseDao.getTableData({
				dbName,
				data,
			});
			res.sum = res.rows.reduce((accumulator, currentValue) => accumulator + currentValue.rechargeNumber, 0);
			res.sum2 = res.rows.reduce((accumulator, currentValue) => accumulator + currentValue.commission, 0);
		}
		if (userInfo.role.includes("copyright")) {
			res = await vk.baseDao.getTableData({
				dbName,
				data,
				whereJson: {
					copyrightId:userInfo._id
				}
			});
			// 对 value 字段进行求和
			res.sum = res.rows.reduce((accumulator, currentValue) => accumulator + currentValue.rechargeNumber, 0);
			res.sum2 = res.rows.reduce((accumulator, currentValue) => accumulator + currentValue.commission, 0);
		}
		console.log("返回数据==》",res);
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
